import React from 'react';
import { WeaTools } from 'ecCom';
import {isEmpty,isEqual} from 'lodash'
import { ELEMENT_TYPES } from '../constants/ActionTypes';
import Workflow from './workflow/';
import MyCalendar from './mycalendar/';
//import MyCalendar from './mycalendar_fs/';
import Rss from './rss/';
import CustomPage from './custompage/';
import News from './news/';
import ReportForm from './reportform/';
import OutData from './outdata/';
import FormModeCustomSearch from './formmodecustomsearch/';
import Picture from './picture/';
import View from './view/';
import MoreNews from './morenews/';
import Stock from './stock/';
import Magazine from './magazine/';
import DocContent from './doccontent/';
import Audio from './audio/';
import Favourite from './favourite/';
import Flash from './flash/';
import ImgSlide from './imgslide/';
import DataCenter from './datacenter';
import Video from './video/';
import Weather from './weather';
import OutterSys from './outtersys/';
import Scratchpad from './scratchpad/';
import Slide from './slide/';
import JobsInfo from './jobsinfo/';
import SearchEngine from './searchengine/';
import CustomMenu from './custommenu/';
import Notice from './notice/';
import Mail from './mail/';
import CoreMail from './coremail/';
import BlogStatus from './blogstatus/';
import Contacts from './contacts/';
import AddWf from './addwf/';
import Task from './task/';
import NewNotice from './newnotice/';
import WorkTask from './worktask/';
import FnaBudgetAssistant from './fnaBudgetAssistant';
import FnaBudgetAssistant1 from './fnaBudgetAssistant1';
//import Plan from './plan/';
import NoReact from './noreact/';
import Cooperation from './cooperation/';
import MeetingCalendar from './meetingcalendar';
import MyProjects from './myprojects';
import LoginNews from './loginnews';
//登录前门户元素
import Login from './login/';
//最新会议元素
import NewMeeting from './newmeeting';
//每日计划元素
import DayPlan from './dayplan';
//我的任务元素
import ProcessTask from './processtask';
//未读文档元素
import UnreadDocs from './unreaddocs';
//最新客户元素
import NewCustomers from './newcustomers';
//消息提醒元素
import MessageReminding from './messagereminding/';
//宁波市中级人民法院文档中心元素
import News_dy from './news_dy/';
/*//通用列表组件
import ElementTable from './elementtable/';*/
//自定义元素
import CustomElement from './customelement/';
//个性化菜单
import QuickEntry from './quickentry/';
//ecode自定义元素
import EcodeElement from './ecodeelement/';
import {openMoreWin} from "../util/common";
import OdocCenter from "./odoccenter";
//排行榜元素
import RankingList from "./rankinglist";
//时间轴元素
import TimeLine from "./timeline";

export default class Element extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            fontSizeMp: {}
        }
        this.getElementStyle = this.getElementStyle.bind(this);
    }

    getElementStyle(id, fontSizeMp){
        const { config } = this.props;
        const { eid } = config.item;
        if(!isEmpty(fontSizeMp) && id == eid){
            this.setState({
                fontSizeMp: fontSizeMp
            })
        }
    }

    shouldComponentUpdate(nextProps, nextState){
        return !isEqual(this.props, nextProps) || !isEqual(this.state, nextState);
    }

    render() {
        const { config } = this.props;
        const { fontSizeMp } = this.state;
        const { eid, ebaseid } = config.item;
        if (/^Custom_/.test(ebaseid)) {
            return <CustomElement ecId={`${this && this.props && this.props.ecId || ''}_CustomElement@7pui54`} key={eid} config={config}/>
        }

        switch (ebaseid) {
            case ELEMENT_TYPES.WORKFLOW:
                return <Workflow ecId={`${this && this.props && this.props.ecId || ''}_Workflow@2ndq70`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.RSS:
                return <Rss ecId={`${this && this.props && this.props.ecId || ''}_Rss@c0crvw`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.CUSTOMPAGE:
                return <CustomPage ecId={`${this && this.props && this.props.ecId || ''}_CustomPage@4e100g`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NEWS:
                return <News ecId={`${this && this.props && this.props.ecId || ''}_News@zcz9yo`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.REPORTFORM:
                return <ReportForm ecId={`${this && this.props && this.props.ecId || ''}_ReportForm@h9z4mx`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.OUTDATA:
                return <OutData ecId={`${this && this.props && this.props.ecId || ''}_OutData@jcyijs`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.FORMMODECUSTOMSEARCH:
                return <FormModeCustomSearch ecId={`${this && this.props && this.props.ecId || ''}_FormModeCustomSearch@p0ne8e`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            //case ELEMENT_TYPES.MESSAGE_REMINDING:
            //case ELEMENT_TYPES.NEW_CUSTOMERS:
            //case ELEMENT_TYPES.NEW_MEETING:
            case ELEMENT_TYPES.MONTH_TARGET:
            //case ELEMENT_TYPES.DAY_PLAN:
            case ELEMENT_TYPES.SUBSCRIBE_KONWLEDG:
                //case ELEMENT_TYPES.UNREAD_DOCS:
                //case ELEMENT_TYPES.UNREAD_COOPERATION:
                //case ELEMENT_TYPES.MY_PROJECTS:
                return <View ecId={`${this && this.props && this.props.ecId || ''}_View@dctoov`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.PICTURE:
                return <Picture ecId={`${this && this.props && this.props.ecId || ''}_Picture@ykws7q`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MORE_NEWS:
                return <MoreNews ecId={`${this && this.props && this.props.ecId || ''}_MoreNews@403cxp`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.STOCK:
                return <Stock ecId={`${this && this.props && this.props.ecId || ''}_Stock@jg69qh`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MAGAZINE:
                return <Magazine ecId={`${this && this.props && this.props.ecId || ''}_Magazine@f7ym68`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.DOC_CONTENT:
                return <DocContent ecId={`${this && this.props && this.props.ecId || ''}_DocContent@09rswr`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.AUDIO:
                return <Audio ecId={`${this && this.props && this.props.ecId || ''}_Audio@lk02wb`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.FAVOURITE:
                return <Favourite ecId={`${this && this.props && this.props.ecId || ''}_Favourite@ulccbh`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.FLASH:
                return <Flash ecId={`${this && this.props && this.props.ecId || ''}_Flash@tuizp5`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.IMGSLIDE:
                return <ImgSlide ecId={`${this && this.props && this.props.ecId || ''}_ImgSlide@u0eetk`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.DATACENTER:
                return <DataCenter ecId={`${this && this.props && this.props.ecId || ''}_DataCenter@xtj6hi`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.VIDEO:
                return <Video ecId={`${this && this.props && this.props.ecId || ''}_Video@jfwhk1`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.WEATHER:
                return <Weather ecId={`${this && this.props && this.props.ecId || ''}_Weather@mzrb9q`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.OUTTERSYS:
                return <OutterSys ecId={`${this && this.props && this.props.ecId || ''}_OutterSys@zklr0p`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.SCRATCHPAD:
                return <Scratchpad ecId={`${this && this.props && this.props.ecId || ''}_Scratchpad@wkgqpp`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.SLIDE:
                return <Slide ecId={`${this && this.props && this.props.ecId || ''}_Slide@1zjynf`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.JOBSINFO:
                return <JobsInfo ecId={`${this && this.props && this.props.ecId || ''}_JobsInfo@ddkgye`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.SEARCHENGINE:
                return <SearchEngine ecId={`${this && this.props && this.props.ecId || ''}_SearchEngine@y1o5x6`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.CUSTOMMENU:
                return <CustomMenu ecId={`${this && this.props && this.props.ecId || ''}_CustomMenu@8dbqll`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NOTICE:
                return <Notice ecId={`${this && this.props && this.props.ecId || ''}_Notice@b5txrt`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MAIL:
                return <Mail ecId={`${this && this.props && this.props.ecId || ''}_Mail@4wkewj`} key={eid} config={config} fontSizeMp={fontSizeMp} />
            case ELEMENT_TYPES.COREMAIL:
                return <CoreMail ecId={`${this && this.props && this.props.ecId || ''}_CoreMail@5d29ov`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.BLOGSTATUS:
                return <BlogStatus ecId={`${this && this.props && this.props.ecId || ''}_BlogStatus@b6birp`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.CONTACTS:
                return <Contacts ecId={`${this && this.props && this.props.ecId || ''}_Contacts@hwsg9p`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.ADDWF:
                return <AddWf ecId={`${this && this.props && this.props.ecId || ''}_AddWf@fygcum`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.TASK:
                return <Task ecId={`${this && this.props && this.props.ecId || ''}_Task@swbbfj`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NEWNOTICE:
                return <NewNotice ecId={`${this && this.props && this.props.ecId || ''}_NewNotice@fj20eb`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.WORKTASK:
                return <WorkTask ecId={`${this && this.props && this.props.ecId || ''}_WorkTask@81s4pp`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.FNABUDGETASSISTANT:
                return <FnaBudgetAssistant ecId={`${this && this.props && this.props.ecId || ''}_FnaBudgetAssistant@320r9c`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.FNABUDGETASSISTANT1:
                return <FnaBudgetAssistant1 ecId={`${this && this.props && this.props.ecId || ''}_FnaBudgetAssistant1@d1c3xt`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            // case ELEMENT_TYPES.PLAN:
            //     return <Plan key={eid} config={config}/>
            case ELEMENT_TYPES.MYCALENDAR:
                return <MyCalendar ecId={`${this && this.props && this.props.ecId || ''}_MyCalendar@9ol1c0`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.UNREAD_COOPERATION:
                return <Cooperation ecId={`${this && this.props && this.props.ecId || ''}_Cooperation@xpzxij`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MEETINGCALENDAR:
                return <MeetingCalendar ecId={`${this && this.props && this.props.ecId || ''}_MeetingCalendar@zcq4qn`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MY_PROJECTS:
                return <MyProjects ecId={`${this && this.props && this.props.ecId || ''}_MyProjects@fa3m81`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.LOGIN:
                return <Login ecId={`${this && this.props && this.props.ecId || ''}_Login@4ihmeh`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.LOGIN_NEWS:
                return <LoginNews ecId={`${this && this.props && this.props.ecId || ''}_LoginNews@miicd0`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NEW_MEETING:
                return <NewMeeting ecId={`${this && this.props && this.props.ecId || ''}_NewMeeting@s0vfe0`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.DAY_PLAN:
                return <DayPlan ecId={`${this && this.props && this.props.ecId || ''}_DayPlan@zy5rkv`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MYTASK:
                return <ProcessTask ecId={`${this && this.props && this.props.ecId || ''}_ProcessTask@y36q9r`} key={eid} config={config}/>
            case ELEMENT_TYPES.UNREAD_DOCS:
                return <UnreadDocs ecId={`${this && this.props && this.props.ecId || ''}_UnreadDocs@nre53y`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NEW_CUSTOMERS:
                return <NewCustomers ecId={`${this && this.props && this.props.ecId || ''}_NewCustomers@dimfkm`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.MESSAGE_REMINDING:
                return <MessageReminding ecId={`${this && this.props && this.props.ecId || ''}_MessageReminding@2om3cl`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.NEW_DY:
                return <News_dy ecId={`${this && this.props && this.props.ecId || ''}_News_dy@vbyzej`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.QUICKEENTRY:
                return <QuickEntry ecId={`${this && this.props && this.props.ecId || ''}_QuickEntry@4wcp1k`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.ECODEELEMENT:
                return <EcodeElement ecId={`${this && this.props && this.props.ecId || ''}_EcodeElement@xatqvj`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.ODOCCENTER:
                return <OdocCenter ecId={`${this && this.props && this.props.ecId || ''}_OdocCenter@wbmy4r`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.RANKINGLIST:
                return <RankingList ecId={`${this && this.props && this.props.ecId || ''}_RankingList@dtw71p`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            case ELEMENT_TYPES.TIMELINE:
                return<TimeLine ecId={`${this && this.props && this.props.ecId || ''}_TimeLine@q2gv1b`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
            default:
                return <NoReact ecId={`${this && this.props && this.props.ecId || ''}_NoReact@tzkvju`} key={eid} config={config} fontSizeMp={fontSizeMp}/>
        }
    }
}
